package com.qfjy.controller.example4;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName BlogController
 * @Description TODO  今日头条（博客系统）主题模式交换机
 * @Author guoweixin
 * @Date 2022/4/2
 * @Version 1.0
 */
@Controller
@RequestMapping("blog")
@Slf4j
public class BlogController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @ResponseBody
    @GetMapping("sendBlog")
    public String sendBlog(@RequestParam("key") String key,@RequestParam("msg") String msg){

        //博客系统后台数据库业务逻辑
        log.info("发送博客--》业务完成-->"+msg+"\t"+key);

        /*
        String exchange  交换机名称
        String routingKey 路由key
        Object object   传输的对象（底层是用二进制传输） -->转成JSON字符串，在另一端获取JSON字符串转成JSON对象
         */
        amqpTemplate.convertAndSend("blogTopicExchange",key,msg);

        return "博客（关注者）发送成功"+msg+"\t"+key;
    }

}
